<!--
 * @Descripttion: 
 * @Author: 夜雨
 * @Email: 448408740@qq.com
 * @Date: 2019-11-28 15:20:33
 * @LastEditTime: 2019-12-05 11:48:04
 -->
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>搜索词统计</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/style/admin.css" media="all">
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-btn-group layui-inline">
                        <button type="button" class="layui-btn layuiadmin-btn-admin mytab2"
                            data-type="date">日期范围</button>
                        <button type="button" class="layui-btn layui-btn-primary layuiadmin-btn-admin mytab2"
                            data-type="month">年月范围</button>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input date" id="date" name="date" placeholder=" - ">
                            <input type="text" class="layui-input date" id="month" placeholder=" - "
                                style="display: none;">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-admin" id="submit">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layuiadmin-btn-admin mytab" data-type="all">全部</button>
                        <button type="button" class="layui-btn layui-btn-primary layuiadmin-btn-admin mytab"
                            data-type="pc">PC端</button>
                        <button type="button" class="layui-btn layui-btn-primary layuiadmin-btn-admin mytab"
                            data-type="m">移动端</button>
                    </div>
                </div>
                <div id="container" style="height: 680px;"></div>
            </div>
        </div>
    </div>

    <script src="/static/layui/layui.js"></script>
    <script src="/static/common/js/layTool.js"></script>
    <script src="/static/common/js/jquery.min.js"></script>
    <script src="__JS__/echarts.min.js" charset="utf-8"></script>
    <script type="text/javascript">
        !function () {
            var ism = 0;
            var date = '';
            var active = {
                all: function () {
                    ism = 0;
                    getData();
                },
                pc: function () {
                    ism = 1;
                    getData();
                },
                m: function () {
                    ism = 2;
                    getData();
                },

                date: function () {
                    $('#date').css('display', 'block').attr('name', 'date');
                    $('#month').css('display', 'none').attr('name', '').val('');
                },
                month: function () {
                    $('#date').css('display', 'none').attr('name', '').val('');
                    $('#month').css('display', 'block').attr('name', 'date');
                }
            };
            var getData = function () {
                $.get('', { ism: ism, date: date }, function (res) {
                    res = res.replace(/&quot;/g, '"');
                    var json = JSON.parse(res);
                    var data_k = [];
                    var data_v = [];
                    for (var i = 0; i < json.length; i++) {
                        data_k.push(json[i]['keyword']);
                        data_v.push(json[i]['count']);
                    }
                    runChart(data_k, data_v);
                });
            };

            getData();
            $('.mytab').click(function () {
                eval('active.' + $(this).attr('data-type') + '()');
                $('.mytab').addClass('layui-btn-primary');
                $(this).removeClass('layui-btn-primary');
            });
            $('.mytab2').click(function () {
                eval('active.' + $(this).attr('data-type') + '()');
                $('.mytab2').addClass('layui-btn-primary');
                $(this).removeClass('layui-btn-primary');
            });
            $('#submit').click(function () {
                date = $('.date[name=date]').val();
                getData();
            });

            layui.use('laydate', function () {
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#date'
                    , range: true
                });
                laydate.render({
                    elem: '#month'
                    , type: 'month'
                    , range: true
                });
            });

        }();
        function runChart(data_k, data_v) {
            var dom = document.getElementById("container");
            var myChart = echarts.init(dom);
            var app = {};
            option = null;
            option = {
                color: ['#3398DB'],
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                        type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                    }
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                xAxis: [
                    {
                        type: 'category',
                        data: data_k,
                        axisTick: {
                            alignWithLabel: true
                        }
                    }
                ],
                yAxis: [
                    {
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '搜索量',
                        type: 'bar',
                        barWidth: '60%',
                        data: data_v
                    }
                ]
            };


            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }
        };
    </script>
</body>

</html>